window.onload = function(){
    getAll()
}
function getAll(){
    let xhr = new XMLHttpRequest()
    /* 
        https://www.bingjs.com:8001/Subject/GetAll    查询全部课程   [GET请求]
    */
    xhr.open("GET",`https://www.bingjs.com:8001/Subject/GetAll`)
    xhr.send()
    xhr.onreadystatechange = function(){
        if(xhr.readyState === 4 && xhr.status === 200){
            let str = JSON.parse(xhr.response)
            console.log(str)
            str.forEach(a=>{
                let tr = document.createElement("tr")
                // 课程编号
                let td_subjectId = document.createElement("td")
                td_subjectId.innerHTML = a.SubjectId
                // 课程名称
                let td_subjectName = document.createElement("td")
                td_subjectName.innerHTML = a.SubjectName
                // 课时
                let td_subjectHour = document.createElement("td")
                td_subjectHour.innerHTML = a.ClassHour
                // 年级编号
                let td_studentGradeId = document.createElement("td")
                td_studentGradeId.innerHTML = a.Grade.GradeId
                // 年级名称
                let td_studentGradeName = document.createElement("td")
                td_studentGradeName.innerHTML = a.Grade.GradeName

                tr.appendChild(td_subjectId)
                tr.appendChild(td_subjectName)
                tr.appendChild(td_subjectHour)
                tr.appendChild(td_studentGradeId)
                tr.appendChild(td_studentGradeName)
                
                tbody.appendChild(tr)
            })
        }
    }
}
